package com.handpay.nocardpay.baselibrary.commbase.view.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;

import com.handpay.nocardpay.baselibrary.R;

/**
 * Created by lyang on 2018/1/16.
 */
public class CustomShowDialog<T extends View> {
    private Context context;
    private DialogCallback dialogcallback;
    private Dialog dialog;
    private Button dialog_ok_btn, dialog_cancel_btn;
    private T mContentView;

    public CustomShowDialog() {
        super();
    }


    public CustomShowDialog(Context context, int view_id,int dialog_theme) {
        this.context = context;
        dialog = new Dialog(context, dialog_theme);
        dialog.setContentView(view_id);
        dialog_ok_btn = (Button) dialog.findViewById(R.id.dialog_ok_btn);
        if (dialog_ok_btn != null){
            dialog_ok_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (dialogcallback != null) {
                        dialogcallback.onClickButtonOK();
                    }
                }
            });
        }
        dialog_cancel_btn = (Button) dialog.findViewById(R.id.dialog_cancel_btn);
        if (dialog_cancel_btn !=null)
            dialog_cancel_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (dialogcallback != null) {
                        dialogcallback.onClickButtonCancel();
                    }
                    dismiss();
                }
            });
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
    }

    public CustomShowDialog(Context context, T view, int dialog_theme) {
        this.context = context;
        this.mContentView = view;
        dialog = new Dialog(context, dialog_theme);
        dialog.setContentView(view);
    }

    public T getContentView() {
        return mContentView;
    }

    public void show() {
        dialog.show();
    }

    public void hide() {
        dialog.hide();
    }

    public void dismiss() {
        dialog.dismiss();
    }

    public interface DialogCallback {
        void onClickButtonOK();

        void onClickButtonCancel();
    }

    public void setDialogCallback(DialogCallback dialogcallback) {
        this.dialogcallback = dialogcallback;
    }

    public Dialog getDialog(){
        return dialog;
    }
}
